package com.suning.sawp.web.controller;

import java.security.Principal;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suning.sawp.constants.ConfigConstants;
import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.dto.aircondition.AirConditionConstants;
import com.suning.sawp.dto.aircondition.AirConditionRequest;
import com.suning.sawp.dto.aircondition.BrandInfo;
import com.suning.sawp.dto.aircondition.MyCustRequest;
import com.suning.sawp.dto.aircondition.MyCustResult;
import com.suning.sawp.dto.aircondition.SchemeInfo;
import com.suning.sawp.dto.aircondition.SchemeResult;
import com.suning.sawp.dto.aircondition.SchemeTempletHouse;
import com.suning.sawp.dto.aircondition.SchemeTempletInfo;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.mainpush.StoreManDto;
import com.suning.sawp.intf.airCondition.AirConditionService;
import com.suning.sawp.intf.storeman.StoreManService;
import com.suning.sawp.service.util.AESUtils;
import com.suning.sawp.web.exception.MobileException;
import com.suning.sawp.web.exception.MyGsonView;

/**
 * 中央空调
 *
 * @author 15050769
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/centralConditioning")
public class AirConditionController extends DjBaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AirConditionController.class);

    @Autowired
    AirConditionService airConditionService;

    @Autowired
    StoreManService storeManService;

    /**
     * 查询客户方案
     *
     * @param index
     * @param size
     * @param mobileNum
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/querySchemeForCust.do")
    public MyGsonView querySchemeForCust(int index, int size, String mobileNum, Principal principal)
            throws MobileException {
        ReturnMsg<List<SchemeResult>> returnMsg = new ReturnMsg<List<SchemeResult>>();
        Object[] args = { principal.getName(), index, size, mobileNum };
        LOGGER.info("querySchemeForCust staffId:{}, index:{}, size:{}, mobileNum:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        // 校验参数合法性
        if (StringUtils.isBlank(mobileNum)) {
            LOGGER.error("querySchemeForCust mobileNum is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
            return setGsonView(returnMsg);
        }
        // 校验店员信息
        if (storeManDto == null) {
            LOGGER.error("querySchemeForCust storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }

        // 校验请求入参
        if (StringUtils.isBlank(storeManDto.getStoreCode()) || StringUtils.isBlank(principal.getName()) || index < 0
                || size <= 0 || size > ConfigConstants.PAGE_SIZE_LIMIT) {
            LOGGER.error("querySchemeForCust  input error for staffid  " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
            return setGsonView(returnMsg);
        }

        String custNum = AESUtils.decrypt(mobileNum, ConfigConstants.AES_KEY);

        ReturnMsg<List<SchemeResult>> result = airConditionService.querySchemeForCust(index, size,
                storeManDto.getStoreCode(), custNum);

        if (result != null && ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            returnMsg.setData(result.getData());
        } else {
            LOGGER.error("querySchemeForCust  input result fail  for staffid  " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0028);
        }
        return setGsonView(returnMsg);
    }

    /**
     * 
     * 根据方案ID查询方案详情
     *
     * @param schemeCode
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/querySchemeInfo.do")
    public MyGsonView querySchemeInfo(String schemeCode, Principal principal) throws MobileException {
        ReturnMsg<SchemeInfo> returnMsg = new ReturnMsg<SchemeInfo>();
        Object[] args = { principal.getName(), schemeCode };
        LOGGER.info("querySchemeInfo staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        // 校验参数
        if (StringUtils.isBlank(schemeCode)) {
            LOGGER.error("querySchemeInfo schemeCode is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
            return setGsonView(returnMsg);
        }
        // 校验店员信息
        if (storeManDto == null) {
            LOGGER.error("querySchemeInfo storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }

        ReturnMsg<SchemeInfo> result = airConditionService.querySchemeInfo(schemeCode);

        if (result != null && ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            returnMsg.setData(result.getData());
        } else {
            LOGGER.error("querySchemeInfo  input result fail  for staffid  " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0028);
        }
        return setGsonView(returnMsg);
    }

    /**
     * 
     * 查询推荐方案
     *
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/querySchemeTemplet.do")
    public MyGsonView querySchemeTemplet(Principal principal) throws MobileException {
        ReturnMsg<List<SchemeTempletHouse>> returnMsg = new ReturnMsg<List<SchemeTempletHouse>>();
        Object[] args = { principal.getName() };
        LOGGER.info("querySchemeTemplet staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        // 校验店员信息
        if (storeManDto == null || StringUtils.isBlank(storeManDto.getOrgBranchCode())) {
            LOGGER.error("querySchemeTemplet storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }
        
        ReturnMsg<List<SchemeTempletHouse>> result = airConditionService.querySchemeTemplet(
                storeManDto.getOrgBranchCode(), "");

        if (result != null && ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            returnMsg.setData(result.getData());
        } else {
            LOGGER.error("querySchemeTemplet  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0028);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0028));
        }
        return setGsonView(returnMsg);
    }

    /**
     * 
     * 根据模板ID查询模板详情
     *
     * @param templetId
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryTempletById.do")
    public MyGsonView queryTempletById(String houseType, String templetId, Principal principal) throws MobileException {
        ReturnMsg<SchemeTempletInfo> returnMsg = new ReturnMsg<SchemeTempletInfo>();
        Object[] args = { principal.getName() };
        LOGGER.info("queryTempletById staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        // 校验参数
        if (StringUtils.isBlank(templetId) || StringUtils.isBlank(houseType)) {
            LOGGER.error("queryTempletById templetId is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
            return setGsonView(returnMsg);
        }

        // 校验店员信息
        if (storeManDto == null) {
            LOGGER.error("queryTempletById storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }

        ReturnMsg<SchemeTempletInfo> result = airConditionService.queryTempletById(templetId, houseType);

        if (result != null && ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            returnMsg.setData(result.getData());
        } else {
            LOGGER.error("queryTempletById  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0028);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0028));
        }
        return setGsonView(returnMsg);
    }

    /**
     * 
     * 查询品牌列表
     *
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryBrandList.do")
    public MyGsonView queryBrandList(Principal principal) throws MobileException {
        ReturnMsg<List<BrandInfo>> returnMsg = new ReturnMsg<List<BrandInfo>>();
        Object[] args = { principal.getName() };
        LOGGER.info("queryBrandList staffId:{}, schemeCode:{}", args);
        List<BrandInfo> obList = new ArrayList<BrandInfo>();
        List<String> brandList = AirConditionConstants.BRAND_CODE_LIST;
        for (String item : brandList) {
            BrandInfo jo = new BrandInfo();
            jo.setBrandCode(item);
            jo.setBrandName(AirConditionConstants.BRAND_MAP.get(item));
            obList.add(jo);
        }

        returnMsg.setData(obList);
        return setGsonView(returnMsg);
    }

    /**
     * 
     * 查询客户历史接待记录
     *
     * @param myCustRequest
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryMyCust.do", produces = "application/json; charset=utf-8")
    @ResponseBody
    public ReturnMsg<List<MyCustResult>> queryMyCust(MyCustRequest myCustRequest, Principal principal)
            throws MobileException {
        ReturnMsg<List<MyCustResult>> returnMsg = new ReturnMsg<List<MyCustResult>>();
        Object[] args = { principal.getName() };
        LOGGER.info("queryMyCust staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        // 校验店员信息
        if (storeManDto == null || myCustRequest == null || StringUtils.isBlank(principal.getName())
                || myCustRequest.getIndex() < 0 || myCustRequest.getSize() <= 0
                || myCustRequest.getSize() > ConfigConstants.PAGE_SIZE_LIMIT) {
            LOGGER.error("queryMyCust storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return returnMsg;
        }

        if (StringUtils.isNotBlank(myCustRequest.getCustNum())) {
            myCustRequest.setCustNum(AESUtils.decrypt(myCustRequest.getCustNum(), ConfigConstants.AES_KEY));
        }
        ReturnMsg<List<MyCustResult>> result = airConditionService.queryMyCust(storeManDto.getStaffId(), myCustRequest);

        if (result != null && ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            returnMsg.setData(result.getData());
        } else {
            LOGGER.error("queryMyCust  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0028);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0028));
        }

        return returnMsg;
    }

    /**
     * 
     * 软删除客户记录
     *
     * @param schemeCode
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/deleteRecord.do")
    public MyGsonView deleteRecord(String schemeCode, Principal principal) throws MobileException {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        Object[] args = { principal.getName(), schemeCode };
        LOGGER.info("deleteRecord staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        // 校验店员信息
        if (storeManDto == null || StringUtils.isBlank(schemeCode)) {
            LOGGER.error("deleteRecord storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }

        ReturnMsg<String> result = airConditionService.deleteRecord(storeManDto.getStaffId(), schemeCode);
        if (result == null || !ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.error("deleteRecord  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0002);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0002));
        }
        return setGsonView(returnMsg);
    }

    /**
     * 提交客户定制信息
     *
     * @param airConditionRequest
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/submitCustMade.do", produces = "application/json; charset=utf-8")
    @ResponseBody
    public ReturnMsg<String> submitCustMade(@RequestBody AirConditionRequest airConditionRequest, Principal principal)
            throws MobileException {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        Object[] args = { principal.getName() };
        LOGGER.info("submitCustMade staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        // 校验店员信息
        if (storeManDto == null) {
            LOGGER.error("submitCustMade storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return returnMsg;
        }

        airConditionRequest.setStaffId(storeManDto.getStaffId());
        airConditionRequest.setStoreCode(storeManDto.getStoreCode());
        airConditionRequest.setStoreName(storeManDto.getStoreName());
        if (StringUtils.isNotBlank(airConditionRequest.getCustNum())) {
            airConditionRequest.setCustNum(AESUtils.decrypt(airConditionRequest.getCustNum(), ConfigConstants.AES_KEY));
        }

        if (StringUtils.isNotBlank(airConditionRequest.getCustNumBack())) {
            airConditionRequest.setCustNumBack(AESUtils.decrypt(airConditionRequest.getCustNumBack(),
                    ConfigConstants.AES_KEY));
        }

        ReturnMsg<String> result = airConditionService.submitCustMade(airConditionRequest);
        if (result == null || !ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.error("submitCustMade  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0002);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0002));
        }

        String staffMobile = storeManDto.getCompanyMobile();
        if (StringUtils.isBlank(staffMobile)) {
            staffMobile = storeManDto.getPersonalMobile();
        }
        if (StringUtils.isBlank(staffMobile)) {
            staffMobile = "我";
        }
        ReturnMsg<String> sendSmsResult = airConditionService.sendSms(airConditionRequest.getCustNum(), staffMobile,
                storeManDto.getStoreName(), storeManDto.getStaffName(), airConditionRequest.getOrderTime(),
                AirConditionConstants.AIRCON.SMS_ORDER_TYPE);
        if (sendSmsResult == null || !ReturnMsg.SUCCESS.equals(sendSmsResult.getRetFlag())) {
            LOGGER.error("submitCustMade  sendSms  input result fail  for staffid  " + principal.getName());
        }
        return returnMsg;
    }

    /**
     * 新增方案
     *
     * @param airConditionRequest
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/submitScheme.do", produces = "application/json; charset=utf-8")
    @ResponseBody
    public ReturnMsg<String> submitScheme(@RequestBody SchemeInfo schemeInfo, Principal principal)
            throws MobileException {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        Object[] args = { principal.getName() };
        LOGGER.info("submitScheme staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        // 校验店员信息
        if (storeManDto == null) {
            LOGGER.error("submitScheme storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return returnMsg;
        }
        schemeInfo.setStaffId(storeManDto.getStaffId());
        schemeInfo.setStoreName(storeManDto.getStoreName());

        if (StringUtils.isNotBlank(schemeInfo.getCustNum())) {
            schemeInfo.setCustNum(AESUtils.decrypt(schemeInfo.getCustNum(), ConfigConstants.AES_KEY));
        }

        if (StringUtils.isNotBlank(schemeInfo.getCustNumBack())) {
            schemeInfo.setCustNumBack(AESUtils.decrypt(schemeInfo.getCustNumBack(), ConfigConstants.AES_KEY));
        }
        ReturnMsg<String> result = airConditionService.submitScheme(schemeInfo, storeManDto.getStoreCode());
        if (result == null || !ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.error("submitScheme  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0002);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0002));
            return returnMsg;
        }
        String staffMobile = storeManDto.getCompanyMobile();
        if (StringUtils.isBlank(staffMobile)) {
            staffMobile = storeManDto.getPersonalMobile();
        }
        if (StringUtils.isBlank(staffMobile)) {
            staffMobile = "我";
        }
        ReturnMsg<String> sendSmsResult = airConditionService.sendSms(schemeInfo.getCustNum(), staffMobile,
                storeManDto.getStoreName(), storeManDto.getStaffName(), "", AirConditionConstants.AIRCON.SMS_TYPE);
        if (sendSmsResult == null || !ReturnMsg.SUCCESS.equals(sendSmsResult.getRetFlag())) {
            LOGGER.error("submitScheme  sendSms  input result fail  for staffid  " + principal.getName());
        }
        return returnMsg;
    }

    /**
     * 
     * 更新方案
     *
     * @param schemeInfo
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/updateScheme.do")
    public MyGsonView updateScheme(@RequestBody SchemeInfo schemeInfo, Principal principal) throws MobileException {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        Object[] args = { principal.getName() };
        LOGGER.info("submitScheme staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        // 校验店员信息
        if (storeManDto == null || StringUtils.isBlank(schemeInfo.getSchemeCode())) {
            LOGGER.error("submitScheme storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }
        schemeInfo.setStaffId(storeManDto.getStaffId());
        schemeInfo.setStoreName(storeManDto.getStoreName());
        if (StringUtils.isNotBlank(schemeInfo.getCustNumBack())) {
            schemeInfo.setCustNumBack(AESUtils.decrypt(schemeInfo.getCustNumBack(), ConfigConstants.AES_KEY));
        }
        if (StringUtils.isNotBlank(schemeInfo.getCustNum())) {
            schemeInfo.setCustNum(AESUtils.decrypt(schemeInfo.getCustNum(), ConfigConstants.AES_KEY));
        }
        ReturnMsg<String> result = airConditionService.updateScheme(schemeInfo);
        if (result == null || !ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.error("submitScheme  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0002);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0002));
        }
        return setGsonView(returnMsg);
    }

    /**
     * 
     * 查询价格是否超出现价
     *
     * @param airConditionRequest
     * @param principal
     * @return
     * @throws MobileException
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/isOverLimit.do")
    public MyGsonView isOverLimit(String commCode, String custNum, String price, Principal principal)
            throws MobileException {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        Object[] args = { principal.getName() };
        LOGGER.info("isOverLimit staffId:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        // 校验店员信息
        if (storeManDto == null || StringUtils.isBlank(commCode) || StringUtils.isBlank(custNum)
                || StringUtils.isBlank(price)) {
            LOGGER.error("isOverLimit storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }
        
        String mobile = "";
        if (StringUtils.isNotBlank(custNum)) {
            mobile = AESUtils.decrypt(custNum, ConfigConstants.AES_KEY);
        }
        ReturnMsg<String> result = airConditionService
                .isOverLimit(commCode, mobile, price, storeManDto.getStoreCode(), principal.getName() );
        if (result == null || !ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.error("querySchemeForCust  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0028);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0028));
        } else {
            returnMsg.setData(result.getData());
        }
        return setGsonView(returnMsg);
    }

    @RequestMapping("/sendSms.do")
    public MyGsonView sendSms(String custNum, String schemeCode, Principal principal) throws MobileException {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        Object[] args = { principal.getName(), custNum, schemeCode };
        LOGGER.info("sendSms staffId:{}, custNum:{}, schemeCode:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        // 校验店员信息
        if (storeManDto == null || StringUtils.isBlank(custNum)) {
            LOGGER.error("sendSms storeManDto is null for " + principal.getName());
            returnMsg.setError(ErrorCodeConstants.ERR_0027);
            return setGsonView(returnMsg);
        }
        String staffMobile = storeManDto.getCompanyMobile();
        if (StringUtils.isBlank(staffMobile)) {
            staffMobile = storeManDto.getPersonalMobile();
        }
        if (StringUtils.isBlank(staffMobile)) {
            staffMobile = "我";
        }
        String mobile = "";
        if (StringUtils.isNotBlank(custNum)) {
            mobile = AESUtils.decrypt(custNum, ConfigConstants.AES_KEY);
        }
        ReturnMsg<String> result = airConditionService.sendSms(mobile, staffMobile, storeManDto.getStoreName(),
                storeManDto.getStaffName(), "", AirConditionConstants.AIRCON.SMS_TYPE);
        if (result == null || !ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.error("querySchemeForCust  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0002);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0002));
        } else {
            returnMsg.setData(result.getData());
        }
        return setGsonView(returnMsg);
    }

}
